using System;
namespace MonsterNet
{
	
	public enum MNQueuedFileStatus
	{
		Waiting = 0,
		Copying = 1,
        Copied = 2,
		Failed = 3
	}
	
	
	public class MNQueuedFile : MNFSObject
	{
		protected MNFSObjectLocation _locationFrom;
		protected MNFSObjectLocation _locationTo;
		protected ulong _sizeInBytes;
		private MNSynchronisedFile _syncFile;
		private int _order;
		private MNQueuedFileStatus _status;
		
		#region getters/setters
		
		/// <summary>
		/// MNFSObjectLocation where the queued file exists
		/// </summary>
		public MNFSObjectLocation LocationFrom {
			get {
				return this._locationFrom;
			}
			set {
				_locationFrom = value;
			}
		}
		
		/// <summary>
		/// MNFSObjecyLocation where the queued file is to be copied
		/// </summary>
		public MNFSObjectLocation LocationTo {
			get {
				return this._locationTo;
			}
			set {
				_locationTo = value;
			}
		}
		
		/// <summary>
		/// Size of the queued file
		/// </summary>
		public ulong SizeInBytes {
			get {
				return this._sizeInBytes;
			}
			set {
				_sizeInBytes = value;
			}
		}
		
		/// <summary>
		/// Order inwhich the queued files are displayed and copied.
		/// </summary>
		public int Order {
			get {
				return this._order;
			}
			set {
				_order = value;
			}
		}	
		
		public void SetRemovedFromPortable() {
			_syncFile.SetExistsAtForLocation(MNFSObjectLocation.Portable, false);
		}		
		
		public void SetExistsAtToLocation(ulong sizeAtToLocation) {
			_syncFile.SetExistsAtForLocation(_locationTo, true);
			_syncFile.SetSizeInBytesForLocation(_locationTo, sizeAtToLocation);
			//TODO: set date modified.
			_status = MNQueuedFileStatus.Copied;
		}
		
		public MNQueuedFileStatus Status {
			get {
				return this._status;
			}
			set {
				_status = value;
			}
		}
		
		public string GetStatusColour {
			get { return GetColourForStatus(_status);	}
		}
		
		public static string GetColourForStatus(MNQueuedFileStatus status) {
			string colour = @"white";
				
				switch (status) {
				case MNQueuedFileStatus.Copied:
					colour = "lightgreen";
					break;
				case MNQueuedFileStatus.Copying:
					colour = "lightblue";
					break;
				case MNQueuedFileStatus.Failed:
					colour = "pink";
					break;
				default:
					colour = @"white"; 
					break;
				}
				return colour;			
		}
		
		public string Extension {
			get { return _syncFile.Extension; }
		}

		
		#endregion		
		
		#region constructor
		
		/// <summary>
		/// New queued file from a MNSynchronisedFile
		/// </summary>
		/// <param name="syncFile">
		/// A <see cref="MNSynchronisedFile"/>
		/// </param>
		/// <param name="locationFrom">
		/// A <see cref="MNFSObjectLocation"/>
		/// </param>
		/// <param name="locationTo">
		/// A <see cref="MNFSObjectLocation"/>
		/// </param>
		public MNQueuedFile(MNSynchronisedFile syncFile, MNFSObjectLocation locationFrom, MNFSObjectLocation locationTo) {
			_locationFrom = locationFrom;
			_locationTo = locationTo;
			
			_name = (string)syncFile.Name.Clone();
			_rootlessPath = (string)syncFile.RootlessPath.Clone();
			_sizeInBytes = syncFile.GetSizeInBytesForLocation(locationFrom);
			
			_syncFile = syncFile;
			
			_order = 0;
			_status = MNQueuedFileStatus.Waiting;
		}
		
		public MNQueuedFile(MNSynchronisedFile syncFile, MNFSObjectLocation locationFrom, MNFSObjectLocation locationTo, int order) : this(syncFile, locationFrom, locationTo) {
			_order = order;
		}
				
		#endregion


	}
}